//1,引入url模块
let url = require("url");
//url模块parse 主要解析 url连接的  'id=123',
//let urlObj = url.parse("http://www.linweiqin.com/query?id=123");  
//第二参数 把 query 变成对象  { id: '123' },
//let urlObj = url.parse("http://www.linweiqin.com/query?id=123",true);  
//第三个参数  host: 'foo',  自动解析域名
//let url_str = url.parse("//foo/bar",true,true);

//url format 方法 URL => URL string
const myURL = new URL("https://www.bing.com/test#/demo?query=1")
let url_obj = url.format(myURL);
console.log(url_obj)

// 后面的参数带了斜杠就是加入,不带斜杠就是替换
let url_four = url.resolve('/one/two/three','four');   //  '/one/two/four'
console.log(url_four) 
let url_one = url.resolve('http://example.com/', '/one');  // 'http://example.com/one'
console.log(url_one)
let url_two = url.resolve("http://example/com/one","two");   //http://example/com/two
console.log(url_two)